async function getLoginInfo() {
  const pm = await fetch('http://localhost:354/api/loginInfo', {
    method: 'get',
    credentials: 'include',
    headers: new Headers({
      'Content-Type': 'application/json',
      'Authorization': sessionStorage.getItem('token')
    })
  });
  const res = await pm.json();
  return res.data;
}

export default {
  namespaced: true,
  state: {
    // 用户信息
    info: {}
  },
  actions: {
    /**
     * @description 设置用户数据
     * @param {Object} context
     * @param {*} info info
     */
    set({
      state,
      dispatch
    }, info) {
      return new Promise(async resolve => {
        // store 赋值
        state.info = await getLoginInfo();
        // end
        resolve()
      })
    },
    /**
     * @description 从数据库取用户数据
     * @param {Object} context
     */
    load({
      state,
      dispatch
    }) {
      return new Promise(async resolve => {
        // store 赋值
        state.info = await getLoginInfo();
        // end
        resolve()
      })
    }
  }
}
